package com.thirteenClassics.convert;

import com.thirteenClassics.context.BaseContext;
import com.thirteenClassics.dto.EntryCatalogQueryDTO;
import com.thirteenClassics.entity.OperationHistory;
import org.mapstruct.*;

import java.time.LocalDateTime;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface OperationHistoryConvertMapper {
    @Mappings({
            @Mapping(source = "currentId", target = "userId"),
            @Mapping(source = "entryCatalogQueryDTO", target = "operatorTime", qualifiedByName = "operatorTimeMap"),
            @Mapping(source = "entryCatalogQueryDTO.bookId", target = "bookId"),
            @Mapping(source = "entryCatalogQueryDTO.index", target = "index"),
            @Mapping(source = "entryCatalogQueryDTO.sentenceIndex", target = "sentenceIndex"),
            @Mapping(source = "entryCatalogQueryDTO.paragraphIndex", target = "paragraphIndex"),
            @Mapping(source = "action", target = "action")
    })
    OperationHistory convert2OperationHistory(EntryCatalogQueryDTO entryCatalogQueryDTO, Long action, Long currentId);

    @Named("userIdMap")
    default Long userIdMap(EntryCatalogQueryDTO entryCatalogQueryDTO) {
        return BaseContext.getCurrentId();
    }

    @Named("operatorTimeMap")
    default LocalDateTime operatorTimeMap(EntryCatalogQueryDTO entryCatalogQueryDTO) {
        return LocalDateTime.now();
    }
}
